#include "mainscene.h"
#include "ui_mainscene.h"
#include <QPainter>
#include <QAction>
#include <mypushbutton.h>
#include <QTimer>
#include <QSound>
MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);
    //设置固定大小
    setFixedSize(400,588);
    //设置图标
    setWindowIcon(QIcon(":/Coin0001.png"));
    //设置标题
    setWindowTitle("fan翻金币！");
    //连接退出信号
    connect(ui->actionquit,&QAction::triggered,this,&QWidget::close);
    //开始按钮
    MyPushButton* startButton=new MyPushButton(":/MenuSceneStartButton.png");
    startButton->setParent(this);
    startButton->move(this->width()*0.5-startButton->width()*0.5,this->height()*0.7);
    chooseSense=new ChooseLevelSense;
    //监听chooselevelsense中发送的信号
    connect(chooseSense,&ChooseLevelSense::backSig,this,[=](){
        chooseSense->hide();
        this->show();
    });
    //加入音效
    QSound *startSound=new QSound(":/TapButtonSound.wav",this);
    connect(startButton,&QPushButton::clicked,[=](){
        //播放开始的音效
        startSound->play();
        //这部分有些问题，按道理应该先下去，后上来，但是只有向上的效果。。。
        startButton->zoom1(10);
        startButton->zoom1(-10);
        //延时进入到选择关卡场景
        QTimer::singleShot(500,this,[=](){
            //进入选择关卡的场景中,hide()函数，将场景隐藏；show函数将场景显示
            this->hide();
            chooseSense->show();
        });
    });
}

MainScene::~MainScene()
{
    delete ui;
}
void MainScene::paintEvent(QPaintEvent *event)
{
    //定义画家
    QPainter painter(this);
    //创建pixmap图像
    QPixmap pix;
    //加载图片
    pix.load(":/PlayLevelSceneBg.png");
    //绘制背景图
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
    //加载标题
    pix.load(":/Title.png");
    //缩放标题图片
    pix.scaled(pix.width()*0.5,pix.height()*0.5);
    //添加标题图片
    painter.drawPixmap(40,30,pix.width(),pix.height(),pix);

}

